package org.come.mouslisten;

import java.math.BigDecimal;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.come.Frame.TestPetJframe1;
import org.come.Frame.Teststatejframe;
import org.come.Jpanel.TestPetJpanel1;
import org.come.Jpanel.TeststateJpanel;
import org.come.bean.ConfigureBean;
import org.come.bean.LoginResult;
import org.come.entity.RoleSummoning;
import org.come.model.Configure;
import org.come.until.AnalysisString;
import org.come.until.Article;
import org.come.until.CutButtonImage;
import org.come.until.GoodsListFromServerUntil;
import org.come.until.UserMessUntil;

import com.tool.PanelDisplay.PetPanelShow1;
import com.tool.PanelDisplay.RolePanelShow;
import com.tool.pet.PetProperty;
import com.tool.role.GetExp;
import com.tool.role.RoleData;
import com.tool.role.RoleProperty;

/***
 * @author 黄建彬
 * @date : 2018年1月3日 下午7:26:09
 *
 *       召唤兽点数切换
 */
public class PetAddPointOneMouslisten1 {
    /**
     * 人物属性添加增加对应的属性
     *
     * @throws Exception
     */
    public static void getplayerValue() {
        Teststatejframe.getTeststatejframe();
        LoginResult loginResult = RoleData.getRoleData().getLoginResult();
        TeststateJpanel teststateJpanel = Teststatejframe.getTeststatejframe().getTeststateJpanel();
        // 判断飞升与否
        int lvltrue = AnalysisString.lvltrue(loginResult.getGrade());
        teststateJpanel.changeSoaringPanel(lvltrue);

        // 设置面板里面的基本参数
        // 种族
        teststateJpanel.getLabrace().setText(loginResult.getRace_name());
        // 设置帮派
        teststateJpanel.getLabgangs().setText(loginResult.getGangname());
        // 称谓
        teststateJpanel.getLabappellation().setText(loginResult.getTitle());
        // 名字
        teststateJpanel.getLabrolename().setText(loginResult.getRolename());
        // id
        if(StringUtils.isNotEmpty(loginResult.getLiangHao())){
            teststateJpanel.getLabappeleid().setText("");
        }else{
            teststateJpanel.getLabappeleid().setText(loginResult.getRole_id() + "");
        }
        // 设置头像
        teststateJpanel.getLabrolehead().setIcon(
                CutButtonImage.getImage("img/head/" + loginResult.getSpecies_id() + ".png", -1, -1));
        // 设置声望
        teststateJpanel.getLabprestige().setText(loginResult.getPrestige().toString());
        // 设置战绩
        teststateJpanel.getLabrecord().setText(loginResult.getPkrecord().toString());
        // 设置等级
        RolePanelShow.changeGrade(loginResult.getGrade());
        // 设置经验
        // 飞升与不飞升有区别
        if (lvltrue <= 3) {
            String curr = loginResult.getExperience().toString();
            String max = RolePanelShow.accessMaxValue(loginResult.getGrade()).toString();

            curr = curr.length() > 7 ? curr.substring(0, curr.length() - 3) + "K" : curr;
            max = max.length() > 7 ? max.substring(0, max.length() - 3) + "K" : max;

            teststateJpanel.getLabEXP().setText(curr + "/"+ max);
        } else {
            teststateJpanel.getLabEXP().setText(loginResult.getExperience().toString());
        }
        // 可分配点数
        teststateJpanel.getLabpointnumber().setText(loginResult.getCanpoint().toString());
        RoleProperty property = RoleProperty.property;
        if (property == null) {
            return;
        }
        // 根骨输入框
        teststateJpanel.getLabrootbone().setText(RoleProperty.getBone(loginResult) + "");
        // 灵性输入框
        teststateJpanel.getLabintelligence().setText(RoleProperty.getSpir(loginResult) + "");
        // 力量输入框
        teststateJpanel.getLabpower().setText(RoleProperty.getPower(loginResult) + "");
        // 敏捷输入框
        teststateJpanel.getLabspeed().setText(RoleProperty.getSpeed(loginResult) + "");
        // 定力输入框
        teststateJpanel.getLabability().setText(RoleProperty.getCalm(loginResult) + "");
        // 设置hp
        teststateJpanel.getLabHP().setText(loginResult.getHp().intValue() + "/" + RoleProperty.getHp(loginResult));
        // 设置mp
        teststateJpanel.getLabMP().setText(loginResult.getMp().intValue() + "/" + RoleProperty.getMp(loginResult));
        // 设置ap
        teststateJpanel.getLabAP().setText(RoleProperty.getAp(loginResult) + "");
        // 设置sp
        teststateJpanel.getLabSP().setText(RoleProperty.getSp(loginResult) + "");
        // 设置cp(定力)
        teststateJpanel.getLabCP().setText(RoleProperty.getCdz(loginResult) + "");
        // 血条
        Article.manxie(loginResult);

    }

    /**
     * 召唤兽增加对应的属性
     */
    public static void getPetValue() {
        // 刷新面板
        showPetValue();
    }

    public static void showPetValue() {
        showPetValue(true);
    }

    /**
     * 进行召唤兽根骨属性面板刷新
     */
    public static void showPetValue(boolean showHead) {
        RoleSummoning pet = UserMessUntil.getChosePetMes();
        if (pet != null) {
            // 属性
            int[] pets = PetProperty.getPetHMASp(pet);
            TestPetJpanel1.getLabHP().setText(pet.getBasishp() + "/" + pets[0]);
            TestPetJpanel1.getLabMP().setText(pet.getBasismp() + "/" + pets[1]);
            TestPetJpanel1.getLabAP().setText(pets[2] + "");
            TestPetJpanel1.getLabSP().setText(pets[3] + "");
            TestPetJpanel1.getLabCP().setText(pets[4] + "");
            // 设置对应的根骨灵性
            TestPetJpanel1.getLabrootbone().setText(pet.getZBone() + "");
            TestPetJpanel1.getLabintelligence().setText(pet.getZSpir() + "");
            TestPetJpanel1.getLabpower().setText(pet.getZPower() + "");
            TestPetJpanel1.getLabspeed().setText(pet.getZSpeed() + "");
            TestPetJpanel1.getLabconcentrate().setText(pet.getZCalm() + "");
            // 可分配点数
            TestPetJpanel1.getLabpointnumber().setText(pet.getCanpoint() + "");

            String curr = pet.getExp().toString();
            String max = GetExp.getBBExp(pet.getTurnRount(), AnalysisString.petLvlint(pet.getGrade())) + "";

            //curr = curr.length() > 7 ? curr.substring(0, curr.length() - 3):"";
            max = max.length() > 7 ? max.substring(0, max.length() - 3) + "K" : max;


            TestPetJpanel1.getLabEXP().setText(curr);//加上max就能显示总经验
            // 忠诚
            TestPetJpanel1.getLabloyalty().setText(pet.getFaithful().toString());
            // 亲密
            TestPetJpanel1.getLabclose().setText(pet.getFriendliness() + "");
            // 等级
            PetPanelShow1.changeGrade(pet.getGrade(), pet.getSummoningname());
            // 刷新血条
            if (showHead) {
                Article.souxie(pet);
            }
            // 判断选中的召唤兽是不是携带的召唤兽
            if (RoleData.getRoleData().getLoginResult().getSummoning_id() != null) {
                // 有携带的召唤兽
                if ((RoleData.getRoleData().getLoginResult().getSummoning_id().compareTo(UserMessUntil.getChosePetMes().getSid())) == 0) {
                    TestPetJpanel1.getTestPetJpanel1().getBtnwar().setText("休息");
                    TestPetJpanel1.getTestPetJpanel1().getBtnwar().setTypeBtn(3);
                } else {
                    TestPetJpanel1.getTestPetJpanel1().getBtnwar().setText("参战");
                    TestPetJpanel1.getTestPetJpanel1().getBtnwar().setTypeBtn(2);
                }
                if (UserMessUntil.getChosePetMes() != null && UserMessUntil.getChosePetMes().getTurnRount() > 3) {//灵犀显示按钮
                    TestPetJpanel1.getTestPetJpanel1().getLingxi().setVisible(true);
                } else {
                    TestPetJpanel1.getTestPetJpanel1().getLingxi().setVisible(false);
                }
            }
            // 将内丹也展示出来
            // 判断这只召唤兽是否有内丹
            if (pet.getInnerGoods() != null && !"".equals(pet.getInnerGoods())) {// 有
                ConfigureBean allConfigure = UserMessUntil.getConfigureBean();
                Map<BigDecimal, Configure> item = allConfigure.getAllConfigure();
                Configure configure = item.get(new BigDecimal(1));


                String[] strings = pet.getInnerGoods().split("\\|");
                for (int i = 0; i < Integer.parseInt(configure.getNdslsx()); i++) {//召唤兽内丹
                    TestPetJpanel1.getLabNedan()[i].setGoodstable(null);
                    TestPetJframe1.getTestPetJframe1().getTestPetJpanel1().remove(TestPetJpanel1.getLabNedan()[i]);
                }
                if (strings.length > 0) {
                    for (int i = 0; i < strings.length; i++) {
                        // 将内丹物品放进去监听中
                        TestPetJframe1.getTestPetJframe1().getTestPetJpanel1().add(TestPetJpanel1.getLabNedan()[i]);
                        TestPetJpanel1.getLabNedan()[i].setGoodstable(GoodsListFromServerUntil.fushis
                                .get(new BigDecimal(strings[i])));
                    }
                }
            } else {// 没有
                ConfigureBean allConfigure = UserMessUntil.getConfigureBean();
                Map<BigDecimal, Configure> item = allConfigure.getAllConfigure();
                Configure configure = item.get(new BigDecimal(1));

                for (int i = 0; i < Integer.parseInt(configure.getNdslsx()); i++) {//召唤兽内丹
                    TestPetJpanel1.getLabNedan()[i].setGoodstable(null);
                    TestPetJframe1.getTestPetJframe1().getTestPetJpanel1().remove(TestPetJpanel1.getLabNedan()[i]);
                }
            }
        }
    }

    /**
     * 清空界面
     */
    public static void clearWindow() {
        TestPetJpanel1.getLabname().setText("");
        // 属性
        TestPetJpanel1.getLabHP().setText("");
        TestPetJpanel1.getLabMP().setText("");
        TestPetJpanel1.getLabAP().setText("");
        TestPetJpanel1.getLabSP().setText("");
        // 设置对应的根骨灵性
        TestPetJpanel1.getLabrootbone().setText("");
        TestPetJpanel1.getLabintelligence().setText("");
        TestPetJpanel1.getLabpower().setText("");
        TestPetJpanel1.getLabspeed().setText("");
        // 可分配点数
        TestPetJpanel1.getLabpointnumber().setText("");
        TestPetJpanel1.getLabEXP().setText("");
        // 忠诚
        TestPetJpanel1.getLabloyalty().setText("");
        // 等级
        TestPetJpanel1.getLablevel().setText("");
        // 内丹
        for (int i = 0; i < 4; i++) {//召唤兽内丹
            TestPetJpanel1.getLabNedan()[i].setGoodstable(null);
            TestPetJframe1.getTestPetJframe1().getTestPetJpanel1().remove(TestPetJpanel1.getLabNedan()[i]);
        }
    }

    /**
     * 当前等级换算
     */
    public static int newgrade(int grade) {
        int newgrade = 0;// 判断人物的等级
        if (grade <= 102) {
            newgrade = grade;
        } else if (grade > 102 && grade <= 210) {
            newgrade = grade - 102 + 14;
        } else if (grade > 210 && grade <= 338) {
            newgrade = grade - 210 + 14;
        } else if (grade > 338 && grade <= 504) {
            newgrade = grade - 338 + 14;
        } else if (grade > 504) {
            newgrade = grade - 504 + 14;
        }
        return newgrade;
    }

    /**
     * 进行确认加点
     *
     * @throws Exception
     */
    public static void sureGetPlayerPoint() {
        // getplayerValue();
        // 刷新装备属性
        RoleProperty.getRoleProperty().equipWearOff();
    }
}
